package crtl;

import java.util.HashMap;
import java.util.Map.Entry;


/**
 *
 * @author marcel meraner
 */
public class BangBangAttackLightCtrl extends BangBangCtrl {

	private boolean _finished = false;

	public BangBangAttackLightCtrl() {
		super();
		System.out.println("BangBang - Attack Light Controller initialized");
	}
	
	@Override
	protected boolean finished() {
		return _finished;
	}

	@Override
	protected Speed navigate() {
		double[] s = readLightSensors();
		s = calcAverage(s);
		
		double min = Double.MAX_VALUE;
		Direction d = Direction.FORWARD;
		HashMap<Direction, Double> values = convertSensorValues(s);
		checkFinished(values);
		
		for (Entry<Direction, Double> entry : values.entrySet()) {
			if (entry.getValue() < min) {
				d = entry.getKey();
				min = entry.getValue();
			}
		}

		return calcSpeed(d, 1);
	}

	private void checkFinished(HashMap<Direction, Double> values) {
		if ((values.get(Direction.S_FRONT_RIGHT) == 0) && (values.get(Direction.S_FRONT_LEFT) == 0)) {
			_finished = true;
		}
	}
	
	public static void main(String[] args) {
		BangBangAttackLightCtrl bbalc = new BangBangAttackLightCtrl();
		System.out.println("runned!!!");
		bbalc.run();
	}
	
}
